package cvi.com.reader.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.orhanobut.hawk.Hawk;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cvi.com.reader.R;
import cvi.com.reader.bean.HotBean;
import cvi.com.reader.bean.constant;

/**
 * Created by 梅涛 on 2020/7/23.
 * <p>
 * 绘本朗读页面适配器
 */

public class PictureBookWorksAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context context;
    private List<String> gridViewBeanList;
    private CollectListener collectListener;

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_grid_picture_book_datail, parent, false);
        return new RecyclerHolder(view);

    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        RecyclerHolder dataHolder = (RecyclerHolder) holder;
      /*  String strUrl = null;
        if (Hawk.contains("ip")) {
            strUrl = Hawk.get("ip");
        }*/

        ImageLoader.getInstance().displayImage("http://" + constant.URL+gridViewBeanList.get(position), dataHolder.imageView);


    }

    @Override
    public int getItemCount() {
        return gridViewBeanList.size();
    }


    public CollectListener getCollectListener() {
        return collectListener;
    }

    public void setCollectListener(CollectListener collectListener) {
        this.collectListener = collectListener;
    }

    public PictureBookWorksAdapter(Context context, List<String> gridViewBeanList) {
        this.context = context;
        this.gridViewBeanList = gridViewBeanList;
    }


    public interface CollectListener {
        public void onCollectClick(String flag, int id);
    }

    class RecyclerHolder extends RecyclerView.ViewHolder {
        ImageView imageView;

        private RecyclerHolder(View itemView) {
            super(itemView);
            imageView = (ImageView) itemView.findViewById(R.id.image);
        }
    }
}
